package aes.gui;

import java.awt.CardLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import aes.general.StudentControl;


/**
 * The Class StudentFrame.The Main Student Frame displayed after Student log's in.
 * 		The Frame Contains UI Elements of available options to Student.
 * 		The contentPane organized as CardLayout contains all Panels 
 * 		that represent different UI elements of Students interaction with System 
 */
public class StudentFrame extends JFrame {

	
	private static final long serialVersionUID = 1L;
	
	
	public static  JPanel contentPane;
	private JPanel MainPanel;
	private JPanel MakeExam;
	private JPanel Grades;
	private JLabel l1;
	private JButton b1;
	private JButton gradebtn;
	
	/**
	 * Constructor.Creates the Java Swing Frame. 
	 */
	public StudentFrame()
	{
		super();
		
		initialize();
	
	}
	
	private void initialize() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 640, 708);
		this.setTitle("Student");
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new CardLayout(0, 0));
		
		MainPanel = new JPanel();
		contentPane.add(MainPanel, "MainPanel");
		MakeExam = new StudentMakeExam(contentPane);
		contentPane.add(MakeExam,"StudentMakeExam");
		MainPanel.setLayout(null);
		
		
		
		l1 = new JLabel("Welcome");
		l1.setFont(new Font("Tempus Sans ITC", Font.BOLD, 21));
		l1.setBounds(258, 11, 98, 29);
		MainPanel.add(l1);
		b1 = new JButton("Make Exam");
		b1.setBounds(221, 76, 178, 23);
		MainPanel.add(b1);
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				CardLayout cl = (CardLayout) (contentPane.getLayout());
				cl.show(contentPane, "StudentMakeExam");
			}
		});
		
		
		
		
		JButton btnLogout = new JButton("Log out");
		btnLogout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				JFrame login = new LoginFrame();
				dispose();
				login.setVisible(true);
			}
		});
		btnLogout.setBounds(221, 245, 178, 23);
		MainPanel.add(btnLogout);
		
		gradebtn = new JButton("Grades & Exams");
		gradebtn.setBounds(221, 119, 178, 23);
		MainPanel.add(gradebtn);
		
		JButton viewExamManual = new JButton("Get Manual Exam Copy");
		viewExamManual.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {	
				StudentGetManualExamCopy getManualCopy  =  new StudentGetManualExamCopy(contentPane);
				contentPane.add(getManualCopy,"StudentGetManualExamCopy");
				CardLayout cl = (CardLayout) (contentPane.getLayout());
				cl.show(contentPane, "StudentGetManualExamCopy");
			}
		});
		viewExamManual.setBounds(221, 164, 178, 23);
		MainPanel.add(viewExamManual);
		gradebtn.addActionListener(new ActionListener() {
			private Vector<Vector<String>> grades;

			public void actionPerformed(ActionEvent arg0) {
				StudentControl.viewExameGrade();
				do{
					grades = StudentControl.getGradesvector();
				}while(grades == null);
				
				if(grades.isEmpty())
				{
					JOptionPane.showMessageDialog(null, "No grades to see", "ok",
							JOptionPane.INFORMATION_MESSAGE);	
					StudentControl.setGradesvector(null);
					
				}
				else{
				Grades = new StudentGradesPanel(contentPane,grades);
				contentPane.add(Grades,"grades");
				CardLayout cl = (CardLayout) (contentPane.getLayout());
				cl.show(contentPane, "grades");
				}
			}
		});
		

	}
}
